import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

type Result = {
  code: number;
  data?: any;
};

type ResultTable = {
  code: number;
  data?: {
    /** 列表数据 */
    list: Array<any>;
    /** 每页显示条目个数 */
    pageSize?: number;
    /** 当前页数 */
    currentPage?: number;
  };
  /** 总条目数 */
  total?: number;
};

/** 获取系统管理-用户管理列表 */
export const getUserList = (data?: object) => {
  return http.request<ResultTable>("post", baseUrlApi("biz/query"), {
    data
  });
};
/** 获取系统管理-用户信息详情列表 */
export const getUserDetailList = (data?: object) => {
  return http.request<ResultTable>("get", baseUrlApi("user/paged-list"), {
    data
  });
};
/** 系统管理-账户停用 */

export const disableUserAccount = (data?: string) => {
  return http.request<ResultTable>("post", baseUrlApi(`user/${data}/stop`));
};
/** 系统管理-账户启用 */
export const enableUserAccount = (data?: string) => {
  return http.request<ResultTable>("post", baseUrlApi(`user/${data}/normal`));
};

export const resetUserPassword = (data?: string) => {
  return http.request<ResultTable>(
    "post",
    baseUrlApi(`user/${data}/reset-password`)
  );
};

/** 系统配置表服务-分页查询 */
export const getSystemConfigList = (params?: object) => {
  return http.request<ResultTable>(
    "get",
    baseUrlApi("system-config/paged-list"),
    {
      params
    }
  );
};

/** 系统配置表服务-编辑 */
export const editSystemConfig = (id: number, data: object) => {
  return http.request<ResultTable>("put", baseUrlApi(`system-config/${id}`), {
    data
  });
};
export const addSystemConfig = (data: object) => {
  return http.request<ResultTable>("post", baseUrlApi(`system-config`), {
    data
  });
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Result>("get", baseUrlApi("role/paged-list"));
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (data?: object) => {
  return http.request<Result>("post", "/list-role-ids", { data });
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>("post", "/role", { data });
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = (params?: object) => {
  return http.request<Result>("get", baseUrlApi("function/paged-list"), {
    params
  });
};
/** 新增菜单 */
export const addMenu = (data?: object) => {
  return http.request<Result>("post", baseUrlApi("function"), {
    data
  });
};
export const editMenu = (id: number, data: object) => {
  return http.request<Result>("put", baseUrlApi(`function/${id}`), { data });
};
/** 删除菜单 */
export const delMenu = (id: number) => {
  return http.request<Result>("delete", baseUrlApi(`/function/${id}`));
};
/** 获取系统管理-部门管理列表 */
export const getDeptList = (data?: object) => {
  return http.request<Result>("post", "/dept", { data });
};

/** 获取系统监控-在线用户列表 */
export const getOnlineLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/online-logs", { data });
};

/** 获取系统监控-登录日志列表 */
export const getLoginLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/login-logs", { data });
};

/** 获取系统监控-操作日志列表 */
export const getOperationLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/operation-logs", { data });
};

/** 获取系统监控-系统日志列表 */
export const getSystemLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/system-logs", { data });
};

/** 获取系统监控-系统日志-根据 id 查日志详情 */
export const getSystemLogsDetail = (data?: object) => {
  return http.request<Result>("post", "/system-logs-detail", { data });
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result>("post", "/role-menu", { data });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (data?: object) => {
  return http.request<Result>("post", "/role-menu-ids", { data });
};
